package com.magicborrow.activity;

import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.easemob.chat.EMChatManager;
import com.magicborrow.R;
import com.magicborrow.utils.UmengUtils;
import com.magicborrow.utils.UserTools;
import com.magicborrow.views.MagicDialog;
import com.umeng.message.PushAgent;

import java.util.Random;

/**
 * Created by Administrator on 2016/5/15.
 */
public class BindMailboxActivity extends BaseActivity implements View.OnClickListener{

    private Intent intent;
    private TextView tvCache;

    private int minCache=0;
    private int maxCache=10;
    private MagicDialog magicDialog;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_install);
        initView();
        initListener();
    }

    private void initView() {
        tvCache = (TextView) findViewById(R.id.tv_cache);
        int random=new Random().nextInt(maxCache - minCache + 1) + minCache;
        tvCache.setText(random==0?"0.1M":"0."+random+"M");
    }

    private void initListener(){
        findViewById(R.id.modifypassword).setOnClickListener(this);
        findViewById(R.id.clearcache).setOnClickListener(this);
        findViewById(R.id.exit).setOnClickListener(this);
        findViewById(R.id.iv_back).setOnClickListener(this);
    }

    @Override
    public void onClick(View v){
        switch (v.getId()){
            case R.id.modifypassword://修改密码
                intent = new Intent();
                intent.setClass(this,VerifyPasswordActivity.class);
                startActivity(intent);
                break;
            case R.id.clearcache://清除缓存
                magicDialog = new MagicDialog(this,"清除缓存");
                magicDialog.show();
                magicDialog.setOnButtonClickListener(new MagicDialog.OnButtonClickListener() {
                    @Override
                    public void onOkClick(Dialog dialog) {
                        tvCache.setText("0M");
                        dialog.dismiss();
                    }

                    @Override
                    public void onCancelClick(Dialog dialog) {
                        dialog.dismiss();
                    }
                });

                break;
            case R.id.exit://退出登录
                magicDialog = new MagicDialog(this,"退出登录");
                magicDialog.show();
                magicDialog.setOnButtonClickListener(new MagicDialog.OnButtonClickListener() {
                    @Override
                    public void onOkClick(Dialog dialog) {
                        UserTools.logOut(BindMailboxActivity.this);
                        EMChatManager.getInstance().logout();
                        dialog.dismiss();
                        MainActivity.instans.setTabHost(0);
                        finish();
                    }

                    @Override
                    public void onCancelClick(Dialog dialog) {
                        dialog.dismiss();
                    }
                });
                break;
            case R.id.iv_back:
                finish();
                break;
        }
    }
}
